<template>
  <div class="wrap">
    <input
      class="input"
      type="checkbox"
      id="checkbox"
      :checked="checked"
      @change="$emit('change', $event.target.checked)"
    />
    <label for="checkbox" class="exterior">
      <div class="check-box">
        <div class="inner">
          <i class="icon iconfont icon-zhengque"></i>
        </div>
      </div>
      <div class="label-text">
        {{ label }}
      </div>
    </label>
  </div>
</template>

<script>
export default {
  model: {
    prop: 'checked',
    event: 'change',
  },
  props: {
    label: {
      type: String,
      default: ''
    },
    checked: {
      type: Boolean,
      default: false
    }
  },
}
</script>

<style scoped lang="less">
.wrap {
  display: inline-flex;
}
.input {
  display: none;
}

.input:checked + label .check-box {
  border-color: #e9b10e;
  .inner {
    background-color: #e9b10e;
    .icon {
      opacity: 1;
    }
  }
}

.exterior {
  position: relative;
  display: inline-flex;
  align-items: center;

  .check-box {
    position: relative;
    width: 18px;
    height: 18px;
    border: 2px solid #848492;
    box-sizing: border-box;
    border-radius: 2px;
    font-size: 0;
    overflow: hidden;
    transition: all 0.3s;

    .inner {
      position: absolute;
      top: 0;
      left: 0;
      width: 14px;
      height: 14px;
      line-height: 14px;
      background-color: transparent;
      transition: all 0.3s;

      .icon {
        opacity: 0;
        display: block;
        font-size: 12px;
        height: 14px;
        line-height: 15px;
        text-align: center;
        font-weight: 600;
        transition: all 0.3s;
      }
    }
  }

  .label-text {
    // flex: 0 0;
    // width: min-content;
    // white-space: nowrap;
    padding-left: 12px;
    height: 18px;
    line-height: 18px;
    font-size: 14px;
    color: #848492;
  }
}
</style>